package com.ysd.entity;

import java.sql.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
 * 用户表
 * @author CJP
 *
 */
@Entity
@Table(name="user")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)//自动增长列
	private Integer uid;//用户id
	private String uloginname;//用户登录名
	private String upassword;//用户密码
	private String uislockout;//是否锁定
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private Date ulisttime;//最后登入时间
	private Date ucreatime;//创建时间
	private Integer upsdwrong;//密码错误次数
	private Date ulocktime;//被锁定时间
	private String uemail;//邮箱
	private String uphone;//手机号
	@JsonIgnoreProperties("ulist")
	@ManyToMany(fetch=FetchType.EAGER) //多对多关系
	@Cascade(value={CascadeType.SAVE_UPDATE}) //级联关系
	@JoinTable(name="userroles", //指定第三张中间表名称
	 //本表主键 roleId 与第三张中间表 user_role_tb 的外键 user_role_tb_role_id 对应.本表与中间表的外键对应关系
	joinColumns={@JoinColumn(name="uid")}, //另一张表中间表的外键的对应关系
	inverseJoinColumns={@JoinColumn(name="rid")})
	@NotFound(action = NotFoundAction.IGNORE)//NotFound : 意思是找不到引用的外键数据时忽略，
	private List<Roles> rlist;
}
